package com.lineng.util;

import java.io.File;

import org.springframework.web.multipart.MultipartFile;

import net.coobird.thumbnailator.Thumbnails;

public class FileUtils {

	public static boolean saveFile(MultipartFile file, String path, int wide, int high) throws Exception {

		// 判断文件是否为空
		if (!file.isEmpty()) {
			try {
				File filepath = new File(path);
				if (!filepath.exists())
					filepath.mkdirs();
				// 文件保存路径
				String Url = path;
				// 转存文件
				file.transferTo(new File(Url));
				// 修改图片
				Thumbnails.of(filepath).size(wide, high).keepAspectRatio(false).toFile(filepath);
				return true;
			} catch (Exception e) {
				e.printStackTrace();
				throw e;
			}
		}
		return false;
	}

}
